<template>
  <BasicModal :width="760" v-bind="$attrs" @register="registerModal" title="订单打印"
              :showCancelBtn="false" :showOkBtn="false" :canFullscreen="false" :centered="true"
              :bodyStyle="{height:'calc(100vh - 120px)', overflowY:'no'}"
  >
    <div class="page-content" id="bi-div">
      <iframe id="buesinessOrderIframe" :src="$url" frameborder="0" width="100%" :style="{height:'calc(100vh - 120px)'}" scrolling="auto"></iframe>
    </div>
  </BasicModal>
</template>
<script lang="ts" name="BusinessPrint" setup>
import { BasicModal, useModalInner } from "/@/components/Modal";
import { useMessage } from "/@/hooks/web/useMessage";
import { onMounted, reactive, ref } from "vue";
import { getToken } from '/@/utils/auth';

let $businessId = ref('');
let $url = ref('');

const $message = useMessage();
// 声明Emits
const emit = defineEmits(['success', 'register']);

// 自动请求并暴露内部方法
onMounted(() => {
  //console.info("onMounted@@@");
});

//表单赋值
const [registerModal] = useModalInner(async (data) => {
  let token = getToken()
  let businessId = data.businessId
  $url.value = `${window._CONFIG['domianURL']}/jmreport/view/775592298281955328?orderId=${businessId}&token=${token}`

  // var frame = '<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" width="100%" height="100%" src="' + url + '"></iframe>';
  // var newNode = document.createElement('div');
  // newNode.innerHTML = frame;
  // newNode.style.height = '1200px';
  // var htmlBody = document.getElementById('bi-div');
  // htmlBody.insertBefore(newNode, htmlBody.firstChild);

  let iframe = document.getElementById('buesinessOrderIframe');
  let json = { title: "订单打印", token: getToken() };
  iframe.contentWindow.postMessage(json, '*');

});

</script>
